package system.company.webservice.ordinary;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;

import system.company.actor.Ordinary_Staff.Ordinary_Staff;
import system.company.base.Objects.Object_status;
import system.company.bountry.display_Forms.Application_Form;
import system.company.bountry.display_Forms.AttendRecord_Form;
import system.company.bountry.display_Forms.Information_Form;
import system.company.bountry.display_Forms.SalaryRecord_Form;
import system.company.bountry.display_Forms.Web_Company_Notices_Form;
import system.company.control.Centers.Operation_Center;

public class Salary_checkout extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	private Ordinary_Staff ordinary_staff=null;
	public Salary_checkout() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	private void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		response.setContentType("text/html;charset=gb2312");
		request.setCharacterEncoding("gb2312");
		//String ID = request.getParameter("ID");
		//String PASSWORD = request.getParameter("password");
		PrintWriter out = response.getWriter();
		response.setStatus(HttpServletResponse.SC_OK);
		HttpSession hsession;
		hsession= request.getSession(true);
		ordinary_staff=(Ordinary_Staff)hsession.getAttribute("ordinary_staff");
		try{
		if(ordinary_staff==null)
		{
			request.getRequestDispatcher("/Common_Page/Entrance_face.jsp").forward(request, response);
		}
		else
		{
			if(ordinary_staff.getStatus()==Object_status.getOrdinary_status())
			{
				SalaryRecord_Form form=null;
				form=Operation_Center.Generate_SalaryRecord_Form(ordinary_staff.getID());
				//out.print(ordinary_staff.getDepartment());
				hsession.setAttribute("form_salary", form);
				request.getRequestDispatcher("/Company_Web/SalaryRecord.jsp").forward(request, response);
			}
			else
			{
				/*************************/
				hsession.isNew();
				hsession.setAttribute("ordinary_staff", ordinary_staff);
				/*********************************/
				if(ordinary_staff.getStatus()==Object_status.getManager_status())
				{
					
				}
				else
				{
					request.getRequestDispatcher("/Common_Page/Entrance_face.jsp").forward(request, response);
				}
			}
		}
	}
		catch(Throwable e)
		{
			System.out.println(e);
		}
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		processRequest(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		processRequest(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
